/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.implementation;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entity.Lists;
import entity.Users;
import services.IListsService;

/**
 *
 * @author smile
 */
@Stateless
@LocalBean
public class ListsService extends GenericServices implements IListsService {
    @PersistenceContext(unitName = "snPU")
    private EntityManager em;


    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public boolean addList(Object object) {
        return this.insert(object);
    }

    @Override
    public boolean deleteList(Object object) {
        return this.delete(object);
    }

    @Override
    public boolean updateList(Object object) {
        return this.update(object);
    }

    @Override
    public List<Lists> getAllLists() {
        return em.createNamedQuery("Lists.findAll").getResultList();
    }

    @Override
    public Lists getListById(Integer id) {
        return em.find(Lists.class, id);
    }
    
    public List<Lists> getListByUserId(Users idUser) {
        try{            
            List<Lists> ls;
            ls = this.em.createNamedQuery("Lists.findByUserId")
                .setParameter("idUser", idUser)
                .getResultList();
            return ls;            
        }catch (Exception e){
            return null;
        } 
    }  

    
}
